package com.chengdu.third.dao;

import com.chengdu.third.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 操作用户接口
 */

@Mapper
@Repository
public interface IUserDao {

    /**
     * 根据id查询用户
     * @param id
     * @return
     */

    public User getUserById(long id);


    /*

    根据用户名查找
     */
    @Select("select * from user where username=#{username}")
    public User  getUserByUsername(String username);


    /**
     * 查找所有用户
     * @return
     */
    @Select("select * from user")
    public List<User> find();

    /**
     * 根据id删除
     * @param id
     */
    @Delete("delete from user where id  = #{id}")
    public void delete(long id);

    /**
     * 根据id修改用户信息
     *
     */
    @Update("update user set username = #{username},password = #{password},phone = #{phone} where id = #{id}")
    public void update(String username,String password,String phone,long id);

    /**
     * 增加用户
     * @param user
     */
    @Insert("insert into  user(`id`,`username`,`password`,`phone`) values(#{id},#{username},#{password},#{phone})")
    public void add(User user);

    @Insert("insert into  user(`username`,`password`,`phone`) values(#{username},#{password},#{phone})")
    public void addUser1(String username,String password,String phone);

    /**
     * 登录验证
     * @param username
     * @param password
     * @return 1为正确,0为错误
     */
    @Select("select count(*) from user where username = #{username} and password = #{password}")
    public int login(@Param("username") String username,@Param("password")String password);
}
